<template>
  <div>
  <!--   面包屑导航条-->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>销售模块管理</el-breadcrumb-item>
    <el-breadcrumb-item>修改密码</el-breadcrumb-item>
  </el-breadcrumb>


    <div class="login-container">
    <el-form :model="user" :rules="userRules" class="loginform_style" label-width="0px" ref="userForm">
      <el-row :gutter="20">
      <el-col :span="40">
      <el-form-item  prop="oldPass">
        <el-input placeholder="输入您的原密码" prefix-icon="el-icon-lock" type="password" v-model="user.oldPass"></el-input>
      </el-form-item>
      </el-col>
      </el-row>
        <el-row :gutter="20">
      <el-col :span="40">
      <el-form-item  prop="newPass">
        <el-input placeholder="输入您的新密码" prefix-icon="el-icon-lock" type="password" v-model="user.newPass"></el-input>
      </el-form-item>
      </el-col>
        </el-row>
<!--      <el-row :gutter="20">-->
<!--        <el-col :span="8">-->
<!--          <el-form-item  prop="Pass">-->
<!--            <el-input placeholder="确认密码" prefix-icon="el-icon-lock" type="password" v-model="user.Pass"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--      </el-row>-->
      <el-form-item class="btns">
        <el-button @click="updatePass" type="primary">修改密码</el-button>
        <el-button @click="resetForm" type="info">重置</el-button>
      </el-form-item>

    </el-form>
    </div>

  </div>
</template>

<script>
    export default {
        name: "UpdatePass",
      data(){
          return{
            user:{
              oldPass:"",
              newPass:"",
              Pass:""
            },
            middle:{},
            userRules: {
              oldPass: [
                {required: true, message: '请输入原密码', trigger: 'blur'},
                {min: 6, message: '请输入6位以上的密码', trigger: 'blur'}
              ],
              newPass: [
                {required: true, message: '请输入新密码', trigger: 'blur'},
                {min: 6, message: '请输入6位以上的密码', trigger: 'blur'}
              ]
            }
          }
      },
      methods:{
        updatePass:function () {

          this.$refs['userForm'].validate((valid) => {
            if (!valid) {
              return
            }
            this.middle.seller=JSON.parse(window.sessionStorage.getItem("seller"));
            console.info(this.middle.seller.id)
            if (this.user.oldPass!=this.user.newPass){

            }
            this.$http.post("/setUserPass?userId="+this.middle.seller.id+"&oldPass="+this.user.oldPass+"&newPass="+this.user.newPass).then((res)=>{
              if (res.data.success) {
                console.info(res.data.result.seller);
                //组件跳转
                this.$router.push('/');
                this.$message.success(res.data.message);
              }else{
                this.$message.error(res.data.message);
              }
            });

          })
        },
        resetForm: function () {
          this.$refs['userForm'].resetFields();
        }
      },
    }
</script>

<style lang="less" scoped>
  .login-container {
    width: 500px;
    height: 500px;
    background-color: #fff;
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 5px;

    .loginform_style {
      padding: 20px 150px ;
      margin-top: 120px;
    }

    .btns {
      display: flex;
      justify-content: center;
    }
  }
</style>

